import { Provide } from '@midwayjs/decorator';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Between, Repository } from 'typeorm';
import { BaseService } from '../../../common/base.service';
import { BillEntity } from '../entity/bill';

@Provide()
export class BillService extends BaseService<BillEntity> {
  @InjectEntityModel(BillEntity)
  billModel: Repository<BillEntity>;

  getModel(): Repository<BillEntity> {
    return this.billModel;
  }

  async tableList(date: string) {
    if (date) {
      const [start, end] = date.split('/');
      return await this.list({
        'verifyDate': Between(new Date(start), new Date(end))
      });
    }

    return await this.list();
  }
}